Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Penalty for secondary energy share deviation in sectors #1762

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

Renato-Rodrigues
Copy link
Member

@Renato-Rodrigues Renato-Rodrigues commented Aug 2, 2024

Purpose of this PR

  • Add support for penalization methods to incentivize the model to maintain similar secondary energy shares across sectors.
  • Addresses issue #322

Features:

  • Implemented support for three penalization methods that work independently of sector-specific formulations regarding fuel use:
    • Square share penalty
    • Square deviation from average share penalty
    • Min-max deviation from average share penalty

Detailed documentation can be found within the code:

*** cm_seFeSectorShareDevMethod "Switch to enable an optimization incentive for sectors to have similar shares of secondary energy fuels and determine the method used for the incentive." 
*** Possible values: off or the method name (sqSectorShare, sqSectorAvrgShare, or minMaxAvrgShare)
***  off               "The model can freely allocate bio/syn/fossil fuels between sectors. If not off, a penalization term is added so sectors are incentivized to apply similar shares of bio-fuels, synfuels, and fossils in each sector."
***  sqSectorShare     "Square share penalty"
***  sqSectorAvrgShare "Square deviation from average share penalty"
***  minMaxAvrgShare   "Min-max deviation from average share penalty"
*** The relative effect of the penalization term in the objective function is scaled to avoid affecting optimization results. This scaling factor can be defined using the switch c_seFeSectorShareDevScale.
$setglobal cm_seFeSectorShareDevMethod  sqSectorAvrgShare !! def = sqSectorAvrgShare  !! regexp = off|sqSectorShare|sqSectorAvrgShare|minMaxAvrgShare
*** c_seFeSectorShareDevUnit "Defines if the penalization term is applied over fuel shares or energy units." 
***  share,  "The square penalization is applied directly to the share values. This results in different-sized regions having varying relative penalization incentives, but the range of penalization values will be more consistent from the solver's perspective."
***  energy, "The square penalization is applied to the share values multiplied by the energy demand. This approach scales penalizations better across different-sized regions, but there is a higher risk of the penalizations being ignored and the shares not being enforced if the value range is too small."
$setglobal c_seFeSectorShareDevUnit  share !! def = share  !! regexp = share|energy

parameter
  c_seFeSectorShareDevScale "scale factor in the objective function of the penalization to incentive sectors to have similar shares of secondary energy fuels."
;
  c_seFeSectorShareDevScale = 1e-3;  !! def = 1e-3
*'
  • The default option is set to sqSectorAvrgShare, as it provides the most stable solution so far with acceptable solving time.

  • The sqSectorShare and sqSectorAvrgShare deviations can be defined using either share units or energy units by setting the option with the switch c_seFeSectorShareDevUnit. The default is set to share.

  • The penalization term in the objective function is scaled to avoid affecting optimization results. This scaling factor can be defined using the switch c_seFeSectorShareDevScale.

Additional Changes:

  • Replaced vm_demFeSector with vm_demFeSector_afterTax in the core share equations, as the marginal effect of the constraints on these shares should not be reflected in final energy marginal prices reported by REMIND.
  • Disabled cm_INCONV_PENALTY_FESwitch to avoid competitive behavior between both penalization methods

Type of change

  • New feature
  • Bug fix
  • Refactoring
  • Fundamental change

Checklist:

  • My code follows the coding etiquette
  • I performed a self-review of my own code
  • I explained my changes within the PR, particularly in hard-to-understand areas
  • All automated model tests pass (FAIL 0 in the output of make test)

Further information (optional):

  • Test runs are here:
    /p/projects/ecemf/REMIND/2040_scenarios/v09_2024_08_02_REMIND_3.3.1/output
    /p/projects/ecemf/REMIND/2040_scenarios/v11_2024_09_02

Renato-Rodrigues and others added 24 commits August 2, 2024 01:53
@JakobBD
Copy link
Contributor

JakobBD commented Sep 19, 2024

Looks good to me. This may be a problem in process-based chemicals. But it seems to be important to the overall model, and I now know that it's there, so we can either live with it, or find a solution for this implementation and chemicals-feedstocks-related SE differences to live alongside each other. Maybe I'll approach you for that in the coming months.

On an unrelated note:
From the documentation, I'd guess that
$\text{sqSectorShare}=\sum_{i=1}^n s_i^2\quad$ with the shares $s_i$ and $\quad\sum_{i=1}^n s_i=1,\quad$ and
$\text{sqSectorAvrgShare}=\sum_{i=1}^n (s_i-\bar{s_i})^2=\sum_{i=1}^n (s_i-\frac{1}{n})^2=\sum_{i=1}^n (s_i^2-\frac{2}{n}s_i+\frac{1}{n^2})=\text{sqSectorShare}-\frac{2}{n}+\frac{1}{n}$,
so they'd only differ by a constant, which shouldn't make a difference to the solver.

Is that so, or did I get the documentation wrong, or did I mess up in my calculations?

core/equations.gms Outdated Show resolved Hide resolved
core/equations.gms Outdated Show resolved Hide resolved
core/equations.gms Outdated Show resolved Hide resolved
core/equations.gms Outdated Show resolved Hide resolved
@robertpietzcker
Copy link
Contributor

Is that so, or did I get the documentation wrong, or did I mess up in my calculations?

@JakobBD I am not sure I understand your calculation.

From briefly looking at it, why should
$\text{sqSectorAvrgShare}=\sum_{i=1}^n (s_i-\bar{s_i})^2=\sum_{i=1}^n (s_i-\frac{1}{n})^2$
hold?

Anyway, I think here is a numeric example that shows that the two differ by more than a fix offset:

if the deviation of the sector-specific bioliq share from the overall average bioliq share is 0, and similarly for fos, and syn, then the squared differences from the sector values to the average values will always be 0.

however, the sum of the squared shares will be very different if you are in a situation with all bio/fos/syn-shares = 0.33 (where it would be number_sectors * 3 * 0.33^2, so number_sectors * 0.326) and a situation where bio and fos shares are 0 and syn-share is 1, where it would be number_sectors * 1^2 = number_sectors

core/preloop.gms Outdated Show resolved Hide resolved
@JakobBD
Copy link
Contributor

JakobBD commented Sep 20, 2024

@robertpietzcker nevermind, I messed up:
The averaging obviously isn't done over the SE types $i$, but over the sectors $j$. So $\sum_{i=1}^n s_{i,j}=1$, but $\sum_{j=1}^n s_{i,j}\neq1$.

But that might raise a different. more severe issue (if I'm not messing up again):

The penalty sqSectorShare not only penalizes unequal distribution over sectors, but also unequal overall shares of SE types.
I.e. a scenario with 100% fossil in all sectors would get a higher penalty than a scenario with 1/3 fos/bio/syn in all sectors.

So in the fossil-dominated world we live in, syn and bio would get a push with no founding.

Is that an effect we want from that penalty switch?

@robertpietzcker
Copy link
Contributor

The penalty sqSectorShare not only penalizes unequal distribution over sectors, but also unequal overall shares of SE types.

yes, which is one of the reasons I prefer the (currently default) "sqSectorAvrgShare " :-)

but you are right, some info about this should be added in the description of "sqSectorShare" - like "this method ALSO creates an unwanted incentive for the model to have equal fos/syn/bio shares"

@JakobBD
Copy link
Contributor

JakobBD commented Sep 20, 2024

which is one of the reasons I prefer the (currently default) "sqSectorAvrgShare " :-)

To me, that seems like the only difference to sqSectorAvrgShare.

I.e.: sqSectorShare can be shown to be sqSectorAverageShare plus a penalty on unequal overall SE shares.

You're saying this only difference is unwanted (and I agree).

Which begs the questions: Is there any advantage to it? If not, then I'd be in favour of deleting it.

(As always, if I'm not messing up).

Calculations:

$\bar{s_i} = \frac{1}{n_j} \sum_j s_{ij}$

and then

$\sum_{i,j} (s_{i,j}-\bar{s_i})^2$

$= \sum_{i,j} (s_{i,j}^2- 2 s_{i,j} \bar{s_i} + \bar{s_i}^2) $

$= \sum_{i,j} s_{i,j}^2 - 2 \sum_{i} \bar{s_i} \sum_{j} s_{i,j} + \sum_{i,j} \bar{s_i}^2$

$= \sum_{i,j} s_{i,j}^2 - 2 n_j \sum_{i} \bar{s_i}^2 + n_j \sum_{i} \bar{s_i}^2 $

$= \sum_{i,j} s_{i,j}^2 - n_j \sum_{j} \bar{s_i}$

@Renato-Rodrigues
Copy link
Member Author

some info about this should be added in the description of "sqSectorShare"

39c2641

@Renato-Rodrigues
Copy link
Member Author

Renato-Rodrigues commented Sep 20, 2024

Which begs the questions: Is there any advantage to it? If not, then I'd be in favour of deleting it.

The alternative formulations are present to compare different levels of complexity and allow runtime comparisons.

The default option selected considers the pros and cons observed so far about these alternatives, but as these formulations should be further improved in subsequent PRs, I prefer to keep the current options in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants